<!DOCTYPE html>
<html>
<head>
    <title>修改</title>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
</head>
<body>
<style>
    html, body{background-color:#FFF!important;}
    .modal-body{background-color:#fff;padding:15px}
    .page-header{margin-top:15px!important;}
    .add_button{border-top:1px solid #eee;padding-top:15px;}
    .config_img {
        height:65px;
        margin-top: 15px;
    }
    .images_del{text-align: center}
    .layui-form-pane .layui-form-label{font-size:12px!important;}
    .modal-body{display: inline-block;padding-bottom:78px;width: 100%}
    .show_multiple{float: left;margin-left:15px;}
    #images_upload{display: inline-block;float: left;padding:0px 10px;}
</style>

<div class="modal-body">

    <fieldset class=" layui-field-title" >
        <legend>详情</legend>
    </fieldset>


    <form class="layui-form layui-form-pane form-horizontal" action="" >


        <!--图文模型&单页模型-->
        <div class="layui-form-item" >
            <a class="layui-form-label" title="内容" href="javascript:;">*内容:</a>
            <div class="layui-col-md8">
                <textarea name="remark" placeholder="内容" class="layui-textarea">{$detail.content}</textarea>
            </div>
        </div>

        <div class="layui-form-item layui-col-md9" style="width:100%">
            <label class="layui-form-label">*图组</label>
            <!--存储上传的图片信息-->
            <div class="layui-input-block">
                <div class="input-group">
                    <div class="input-group show_multiple row">
                        {volist name="$detail['images']" id="vo1"}
                        <div class="newimg"><img src="{$vo1}" ><input type="hidden" name="images[]" value="{$vo1}"></div>
                        {/volist}
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-col-md9">
            <label class="layui-form-label">时间</label>
            <div class="layui-col-md8">
                <input type="text" name="show_time" class="layui-input test-item" placeholder="时间" value="{$detail.addtime}">
            </div>

        </div>

    </form>

</div>
<div class="add_button">
    <div class="layui-form-item">
        <div class="layui-col-md-offset1">
            <a type="button" class="layui-btn layui-btn-primary" href="{:URL('project/comment/index')}?pro_id={$detail.pro_id}&library={$library}" >返回</a>
            <!--<button type="button" class="layui-btn" id="newsave" >保存</button>-->
        </div>
    </div>
</div>

<script>
    var newModal = new yii.modal();
    $(".show_multiple").on("click",".images_del",function () {
        $(this).parent().remove();
    })
    //多图片上传
    $("#images_upload").click(function () {
        $(newModal.getid()).show();
        newModal.initialization({
            url: "{:URL('common/Upload/index')}",
            type: "post",
            data:{
                type:'detail',
                multiple:'multiple'
            }
        });
    });

    newModal.on("multiple",function(data){
        var images = '';
        $(newModal.getid()).find("#data-area .newimages .active img").each(function () {
            images += '<div class="newimg"><img src="'+$(this).attr('src')+'" ><input type="hidden" name="images[]" value="'+$(this).attr('src')+'"><div class="images_del" >删除</div></div>';
        })
        $(newModal.getid()).hide();
        //遮罩层隐藏
        //$('#nowMainProjectDataForm').modal('hide');
        $(".modal-backdrop").remove();
        $(newModal.getid()).find(".modal").hide();
        $(".show_multiple").append(images);
    });
    //多图上传


    layui.extend({
        tinymce: '/static/tinymce/tinymce'
    });
    layui.use(['form','tinymce','laydate','transfer'], function() {
        var form = layui.form
            , layer = layui.layer;
        var tinymce = layui.tinymce;
        var transfer = layui.transfer;
        var laydate = layui.laydate;

        lay('.test-item').each(function(){
            laydate.render({
                elem: this
                ,trigger: 'click'
                ,type:'datetime'
            });
        });
        tinymce.render({
            elem:'#content',
            height: 600,
            images_upload_handler: function (blobInfo, succFun, failFun) {
                var xhr, formData;
                var file = blobInfo.blob();//转化为易于理解的file对象
                xhr = new XMLHttpRequest();
                xhr.withCredentials = false;
                xhr.open('POST', "{:URL('/common/upload/textUpload')}");
                xhr.onload = function() {
                    var json;
                    json = JSON.parse(xhr.responseText);
                    succFun(json.path);
                };
                formData = new FormData();
                formData.append('file', file, file.name );//此处与源文档不一样
                xhr.send(formData);
            }
        },(opt, edit) => {});


        $("#newsave").click(function () {
            var content = tinymce.get('#content').getContent();
            var data = $("form").serializeArray();
            data.push({name: "content", value: content});
            $.ajax({
                type:'post',
                url:"{:URL('project/Figure/save')}",
                data:data,
                dataType:'JSON',
                success:function (res) {
                    if(res.code!=0){
                        layer.alert(res.msg);
                    }else{
                        window.location.href = "{:URL('project/Figure/index')}?pro_id={$detail.pro_id}";
                    }
                },
                error:function (res) {
                }
            });
        });

        layui.form.render('select');
        form.render();
    });


    //文件页面
    $("#upload").click(function () {
        $(newModal.getid()).show();
        newModal.initialization({
            url: "{:URL('common/upload/index')}",
            type: "post",
            data:{
                type:'detail'
            }
        });
    });

    newModal.on("upload",function(data){
        var images = '';
        $(newModal.getid()).find("#data-area .newimages .active img").each(function () {
            images = $(this).attr('src');
            return false
        })
        $(newModal.getid()).hide();
        //$(".modal-backdrop").remove();
        //$('#nowMainProjectDataForm').modal('hide');
        $(newModal.getid()).find(".modal").hide();
        $("#thumb").val(images);
        $(".config_img").attr("src",images)
    });
</script>

</body>
</html>